<?
/*----------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	小飞熊新一代下载系统
          	代码编写：小飞熊	版权所有：小飞熊[L.F.Bear]
				官方网站/技术支持：http://www.lfbear.cn
------------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	L.F.Bear's New Download Sysytem
          	Powered by L.F.Bear  Copyright L.F.Bear's Home(R)
               Official Web/Support：http://www.lfbear.cn
-----------------------------------------------------------------------*/

//本页脚本功能：友情链接
$thispage="link.php";
echo ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
require("../function.php");
require("check.php");

if ($_COOKIE[status]=="login" && $_SESSION[login]=="yes")
{
$yourname=$_COOKIE[yourname];
$level=$_SESSION[level];
if(!checklevel($level,"system"))
	{$msg_title="系统信息：权限不足";
	$msg_link="login.php";
	$msg="您无法进行此项管理操作！<br><br>原因：您所在的用户组没有该权限。<br><br>";
	weblog("友情链接","无权限操作，被系统拦截！","red",$yourname,"触发页面：link.php");
	require("error.php");
	die;}

$action=$_GET[action];
switch ($action){
case plus:
$act="?".$action;
$msg_="重要信息";
$msg_color="#FF8C1A";
require("msg.php");
print <<<EOT
<link href="images/css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.massage{color:#993399;
cursor:help;
text-decoration:none;}
.subtitle{
color:#3300FF;
font-family:"宋体";
font-size:12px;
font-weight:bold;}
-->
</style>
<body bgcolor="#DDF1FF">
<form method="post" action="link.php?action=plus_save">
<table width="750" border="1" align="center" cellpadding=4 cellspacing=0 bordercolor="#ACC1FC" heoght=400>
  <tr bgcolor='#ACC1FC'>
    <td colspan="2"><a class="title">欢迎您：$yourname 登陆管理程序</a></td>
  </tr>
  <tr bgcolor='#FFFFFF'>
    <td colspan="2" bgcolor="#EBE9ED" class="comments-title">友情链接--&gt;添加链接</td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td width="150">网站名称：</td>
       <td width="550"><input name="web_name" type="text" id="web_name" size="35"></td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td>网站地址：</td>
       <td><input name="web_http" type="text" id="web_http" size="35" value="http://"></td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td>文字说明：</td>
       <td><input name="web_intro" type="text" id="web_intro" size="35"></td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td>Logo地址：</td>
       <td><input name="web_logo" type="text" id="web_logo" size="35" value="http://">
       <input name="logo" type="checkbox" id="logo" value="nologo" onClick="this.form.web_logo.disabled=this.checked;" >
       文字链接(无Logo地址)</td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td colspan="2" align="center"><input type="submit" name="Submit" value="提交">
  	     <input type="reset" name="Submit2" value="重置"></td>
  </tr>
</table>
</form>
EOT;
require("footer.php");
break;
case plus_save:

//提取变量
$web_name=$_POST[web_name];
ckchar($web_name);
$web_http=$_POST[web_http];
ckchar($web_http);
$web_intro=$_POST[web_intro];
ckchar($web_intro);
$web_logo=$_POST[web_logo];
$logo=$_POST[logo];

if($logo=="nologo") $web_logo=0;

$sep="|";
$filename="../include/linkinfo.php";

if(file_exists($filename))
$info="y".$sep.$web_name.$sep.$web_http.$sep.$web_intro.$sep.$web_logo."\n";
else 
$info="<? die(\"Forbidden Access!\");?>"."\n"."y".$sep.$web_name.$sep.$web_http.$sep.$web_intro.$sep.$web_logo."\n";
writef($filename,$info,"a");
	{$msg_title="友情链接：添加成功";
	$msg_link="link.php?action=plus";
	$msg="友情链接[$web_name]添加成功<br><br>点击“确定”返回继续添加<br><br>";
	weblog("友情链接","链接[$web_name]添加成功","green",$yourname,"触发页面：link.php?action=plus");
	require("ok.php");
	die;}
break;

case edit:
$filename="../include/linkinfo.php";
if (file_exists($filename)) {
	$linkdata=file($filename);
	$link_num=count($linkdata);
for($i=1;$i<$link_num;$i++){
	$link_info=explode("|",$linkdata[$i]);
	if($link_info[0]=="y") $yes="<font color=green>开启</font>";else $yes="<font color=red>关闭</font>";
$link.="    <tr bgcolor='#FFFFFF'>
	      <td align=\"center\">$yes</td>
      <td align=\"center\"><a href=$link_info[2] target=\"_blank\">$link_info[1]</a></td>
      <td align=\"center\">$link_info[2]</td>
      <td align=\"center\">$link_info[3]</td>
      <td align=\"center\"><input type=\"radio\" name=\"op\" value=\"edit_$i\">
      选择编辑</td>
      <td align=\"center\"><input type=\"radio\" name=\"op\" value=\"del_$i\" onClick=\"alert('不可恢复，请慎重选择！其实您可以考虑把它的状态更改为“关闭”的...');\">
      选择删除</td>
    </tr>";
}}
else $link="<tr bgcolor='#FFFFFF'><td colspan=\"6\" align=\"center\">暂时没有链接项目可以管理</td></tr>";
if($link_num==1) $link="<tr bgcolor='#FFFFFF'><td colspan=\"6\" align=\"center\">暂时没有链接项目可以管理</td></tr>";

$act="?".$action;
$msg_="重要信息";
$msg_color="#FF8C1A";
require("msg.php");
print <<<EOT


<link href="images/css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.massage{color:#993399;
cursor:help;
text-decoration:none;}
.subtitle{
color:#3300FF;
font-family:"宋体";
font-size:12px;
font-weight:bold;}
-->
</style>
<body bgcolor="#DDF1FF">
<form method="post" action="link.php?action=edit_next">
  <table width="750" border="1" align="center" cellpadding=4 cellspacing=0 bordercolor="#ACC1FC" heoght=400>
    <tr bgcolor='#ACC1FC'>
      <td colspan="6"><a class="title">欢迎您：$yourname 登陆管理程序</a></td>
    </tr>
    <tr bgcolor='#FFFFFF'>
      <td colspan="6" bgcolor="#EBE9ED" class="comments-title">友情链接--&gt;管理链接</td>
    </tr>

    <tr bgcolor='#FFFFFF'>
      <td width="30" align="center">状态</td>
      <td width="120" align="center">网站名称</td>
      <td width="120" align="center">网站地址</td>
      <td width="160" align="center">文字说明</td>
      <td width="128" align="center">编辑链接</td>
      <td width="130" align="center">删除链接</td>
    </tr>
    	$link
<tr bgcolor='#FFFFFF'>
      <td colspan="6" align="center"><input type="submit" name="Submit" value="提交">
      <input type="reset" name="Submit2" value="重置"></td>
    </tr>
  </table>
</form>

EOT;
require("footer.php");
break;

case edit_next:

$op=$_POST[op];
$op=explode("_",$op);
switch($op[0])
	{
	case "edit":
	$filename="../include/linkinfo.php";
	$linkdata=file($filename);
	$link_num=count($linkdata);
	$link_info=explode("|",$linkdata[$op[1]]);
	if($link_info[0]=="y") $ck="checked"; else $unck="checked";
$act="?".$action;
$msg_="重要信息";
$msg_color="#FF8C1A";
require("msg.php");
print <<<EOT
	<link href="images/css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.massage{color:#993399;
cursor:help;
text-decoration:none;}
.subtitle{
color:#3300FF;
font-family:"宋体";
font-size:12px;
font-weight:bold;}
-->
</style>
<body bgcolor="#DDF1FF">
<form method="post" action="link.php?action=edit_save">
<table width="750" border="1" align="center" cellpadding=4 cellspacing=0 bordercolor="#ACC1FC" heoght=400>
  <tr bgcolor='#ACC1FC'>
    <td colspan="2"><a class="title">欢迎您：$yourname 登陆管理程序</a></td>
  </tr>
  <tr bgcolor='#FFFFFF'>
    <td colspan="2" bgcolor="#EBE9ED" class="comments-title">友情链接--&gt;编辑链接
    <input name="edit_num" type="hidden" id="edit_num" value=$op[1]></td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td width="150">开启状态：</td>
       <td width="550"><input type="radio" name="open" value="y" $ck>
         开启
           <input type="radio" name="open" value="n" $unck>
           关闭</td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td>网站名称：</td>
       <td width="550"><input name="web_name" type="text" id="web_name" value="$link_info[1]" size="35"></td>
    </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td>网站地址：</td>
       <td><input name="web_http" type="text" id="web_http" value="$link_info[2]" size="35"></td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td>文字说明：</td>
       <td><input name="web_intro" type="text" id="web_intro" value="$link_info[3]" size="35"></td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td>Logo地址：</td>
       <td><input name="web_logo" type="text" id="web_logo" value="$link_info[4]" size="35">
       （“0”表示没有Logo）</td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
  	   <td colspan="2" align="center"><input type="submit" name="Submit" value="提交">
  	     <input type="reset" name="Submit2" value="重置"></td>
  </tr>
</table>
</form>
EOT;
require("footer.php");
	break;
	
	case "del":
		
	$filename="../include/linkinfo.php";
	$linkdata=file($filename);
	$link_num=count($linkdata);
$link_info="<? die(\"Forbidden Access!\");?>"."\n";
for($i=1;$i<$link_num;$i++){
if($i==$op[1])
	$link_info.="";
	else 
	$link_info.=$linkdata[$i];
}
writef($filename,$link_info,"w");
	{$msg_title="友情链接：删除成功";
	$msg_link="link.php?action=edit";
	$msg="友情链接删除成功<br><br>点击“确定”返回继续添加<br><br>";
	weblog("友情链接","删除链接成功","green",$yourname,"触发页面：link.php?action=edit");
	require("ok.php");
	die;}
	break;
default:
	
	{$msg_title="系统信息：参数错误";
	$msg_link="link.php?action=edit";
	$msg="无效的操作动作！<br><br>原因：请您先选择要编辑/删除的条目！<br><br>";
	require("error.php");
	die;}
	
break;
	}
break;

case edit_save:
$edit_num=$_POST[edit_num];
$web_name=$_POST[web_name];
ckchar($web_name);
$web_http=$_POST[web_http];
ckchar($web_http);
$web_intro=$_POST[web_intro];
ckchar($web_intro);
$web_logo=$_POST[web_logo];
$open=$_POST[open];

$sep="|";
$info=$open.$sep.$web_name.$sep.$web_http.$sep.$web_intro.$sep.$web_logo."\n";

$filename="../include/linkinfo.php";
	$linkdata=file($filename);
	$link_num=count($linkdata);
$link_info="<? die(\"Forbidden Access!\");?>"."\n";
for($i=1;$i<$link_num;$i++){
if($i==$edit_num)
	$link_info.=$info;
	else 
	$link_info.=$linkdata[$i];
}
writef($filename,$link_info,"w");
	{$msg_title="友情链接：更改成功";
	$msg_link="link.php?action=edit";
	$msg="友情链接[$web_name]更改成功<br><br>点击“确定”返回继续添加<br><br>";
	weblog("友情链接","链接[$web_name]更改成功","green",$yourname,"触发页面：link.php?action=edit");
	require("ok.php");
	die;}

break;
default:
die("Error Parameter,Forbidden Access!");
break;
}}
?>